﻿//-----------------------------------------------------------------------
// <copyright file="BootStrapDatabaseFixture.cs" company="OverrideThis">
//     Copyright (c) 2010 OverrideThis.com
// </copyright>
//-----------------------------------------------------------------------
namespace OverrideThis.ContactManager.Tests.Database
{
    using System;
    using NUnit.Framework;
    using OverrideThis.ContactManager.Domain;
    using OverrideThis.Core.Infrastucture.Repository;
    using OverrideThis.Core.Infrastucture.Repository.Impl;
    using StructureMap;

    [TestFixture]
    class BootStrapDatabaseFixture
    {
        [Test]
        public void Build_DatabaseSchema_ForDevelopment()
        {
            new BootStrapper().BootStrap("connKey");
            var sessionFactory = ObjectFactory.GetInstance<NhSessionFactory>();
            sessionFactory.BuildSchema();
            InitializeTestData();
        }

        private void InitializeTestData()
        {
            var repository = ObjectFactory.GetInstance<IRepository>();
            repository.WithTransaction(
                r => {
                    r.SaveOrUpdate(new Person { Firstname = "Hernandez", Lastname = "Roberto", Country = Country.DominicanRepublic , BirthDate = new DateTime(1974,12,18)});
                    r.SaveOrUpdate(new Person { Firstname = "Hernandez", Lastname = "Isaura", Country = Country.USA, BirthDate = new DateTime(2004, 9, 14) });
                    r.SaveOrUpdate(new Person { Firstname = "Hernandez", Lastname = "Regina", Country = Country.USA, BirthDate = new DateTime(2007, 6, 5) });
                });
        }
    }
}
